package books.ThinkingInJava.src.Chapter14;

import books.ThinkingInJava.src.Tools.Output;

public class TestRTTI<T> {
    T a;

    public TestRTTI(T t) {
        a = t;
        Output.println(a);
    }

    static void printInfo(Class cc) {
        Output.println("Class name: " + cc.getName() + " is interface  " + cc.isInterface());
        Output.println("Simple name:" + cc.getSimpleName());
        Output.println("Canonical name: " + cc.getCanonicalName());
        Output.println("");
    }

    public static void main(String[] args) {
//        TestRTTI<Exception> tf = new TestRTTI<>(new Exception());
        Class c = null;
        try {
            c = Class.forName("Chapter14.FancyToy");
        } catch (ClassNotFoundException cne) {
            Output.print("Cant't find FancyToy");
            System.exit(1);
        }
        printInfo(c);
        for (Class face : c.getInterfaces()) {
            printInfo(face);
        }
        Class up = c.getSuperclass();
        Object obj = null;

        try {
            obj = c.newInstance();
        } catch (InstantiationException ie) {
            Output.print("Can't instantiate.");
            System.exit(1);
        } catch (IllegalAccessException iae) {
            Output.println("Can't access.");
            System.exit(1);
        }

        printInfo(obj.getClass());
    }

}
